Skip to content
This repository has been archived by the owner on Feb 21, 2020. It is now read-only.

Don't leak the injector instance into the class. #14

Merged
merged 5 commits into from
Jan 22, 2016

Conversation

groner
Copy link
Collaborator

@groner groner commented Jan 11, 2016

I noticed this while scratching my Injector.alias() itch (#13).

@groner
Copy link
Collaborator Author

groner commented Jan 11, 2016

Prior to this change, Injector.sub() instances would provide an 'injector' service if one had been created by instantiating Injector or one of it's bases with provide_self=True. This was the wrong injector, but if it wasn't closed, code may have executed using the other injector without breaking. Now Injector.sub() instances will have no injector, because Injector.sub() uses it's arguments to customize the subinjector.

We need another way to allow access to the injector in this case. Here are some ideas:

  1. Revise the Injector.sub() API to allow provide_self to be specified in some way (maybe just a reserved kwarg).
  2. Allow the provide_self bit to be configured on the injector class.
  3. Stop pretending we can provide a sandbox in python and provide the injector always.

My preference is for 3. It might seem radical, but I really don't think it is.

@rduplain
Copy link
Owner

Thanks for this. We can go with 3 given how subinjectors work.

@groner
Copy link
Collaborator Author

groner commented Jan 13, 2016

I'll come up with a patch.

@groner
Copy link
Collaborator Author

groner commented Jan 13, 2016

I see the docs need to be updated. I'm working on that now.

@groner
Copy link
Collaborator Author

groner commented Jan 13, 2016

So now we don't support provide_self=False with subinjectors. Should we just deprecate provide_self=False?

@rduplain
Copy link
Owner

Yes.

@groner
Copy link
Collaborator Author

groner commented Jan 13, 2016

I've merely omitted any discussion of Injector(provide_self=False) in the Injector docstring.

Should we document the deprecation or add something like this?

    if not provide_self:
        warnings.warn(DeprecationWarning('provide_self=False is not supported'))

@rduplain
Copy link
Owner

DeprecationWarning should be enough.

@groner groner merged commit 837d951 into rduplain:master Jan 22, 2016
groner added a commit that referenced this pull request Jan 22, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants